﻿function PageTracker() {
    var postDomain = "http://click.dangdang.com/";
    var invoke_server = function(m_id, o_id, refer_url, url, type) {

        if (o_id == null)
            o_id = '';
        var img = new Image();
        img.src = postDomain + 'page_tracker.aspx?m_id=' + m_id
             + '&o_id=' + o_id
             + '&refer_url=' + escape(refer_url)
             + '&url=' + escape(url)
             + '&type=' + type
             + "&r=" + Math.random();
    }


    this.trackPageview = function() {
        var url = location.href;
        var referrer = document.referrer;
        if (!referrer) {
            try {
                if (window.opener) {
                    referrer = window.opener.location.href;
                }
            }
            catch (e) { }
        }
        invoke_server(null, null, referrer, url, '1');
    }

    this.trackPingPHP = function(url) {
        var referrer = document.referrer;
        if (!referrer) {
            try {
                if (window.opener) {
                    referrer = window.opener.location.href;
                }
            }
            catch (e) { }
        }
        invoke_server(null, null, referrer, url, '5');
    }
}

if (typeof (ddclick_page_tracker) == "undefined") {
    ddclick_page_tracker = new PageTracker();
    ddclick_page_tracker.trackPageview();
}